﻿namespace MotionFramework.Singleton
{
	using System;
	using System.Collections;
	using System.Collections.Generic;

	/// <summary>
	/// 单例模板
	/// </summary>
	public abstract class Singleton<T> where T : class
	{
		#region Fields

		/// <summary>
		/// The instance.
		/// </summary>
		private static T _instance;

		#endregion

		#region Properties

		/// <summary>
		/// Gets the instance.
		/// </summary>
		/// <value>The instance.</value>
		public static T Instance
		{
			get
			{
				if ( _instance == null )
				{
					_instance = Activator.CreateInstance<T>();
				}
				return _instance;
			}
		}

		#endregion

		#region Methods

		/// <summary>
		/// Use this for DestroySingleton.
		/// </summary>
		protected void DestroySingleton()
		{
			_instance = null;
		}

		#endregion
	}
}
